package com.sgb.kjwl.view.ui.adapter.pick;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.QuotationListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class QuotationListAdapter extends BaseRecycleAdapter<QuotationListEntity> {

    private TextView title_view;
    private TextView et_price;
    private ISumPrice iSumPrice;
    private TextView tvNum;

    public QuotationListAdapter(Context context, List<QuotationListEntity> datas) {
        super(context, R.layout.item_list_of_quotations, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final QuotationListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        title_view = holder.itemView.findViewById(R.id.title_view);
        et_price = holder.itemView.findViewById(R.id.et_price);
        tvNum = holder.itemView.findViewById(R.id.tv_num);
        tvNum.setText(entity.getNum()+"");
        if (holder.getAdapterPosition() == 0) {
            title_view.setVisibility(View.VISIBLE);
        }
        et_price.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                entity.setBigDecimal(editable.toString());
            }
        });
    }

    public interface ISumPrice {
        void onSum(List<QuotationListEntity> datas);
    }

    public void ISumPrice(ISumPrice iSumPrice) {
        this.iSumPrice = iSumPrice;
    }

    public List<QuotationListEntity> getChangeData(){
        return datas;
    }
}
